import { defineConfig } from "vite";
import vuePlugin from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import { Env } from "../utils/env";
import { App_Env_Enum } from "../enum/app.enum";
import { resolve } from "path";
import TransCssModulePlugin from "../plugins/transCssModulePlugin";

const root = resolve("src/application");

export default defineConfig({
  mode: Env.getEnv(App_Env_Enum.NODE_ENV),
  root,
  resolve: {
    alias: {
      "@scripts": resolve("scripts"),
      "@utils": resolve("utils"),
      "@config": resolve("config"),
      "@types": resolve("types"),
      "@enum": resolve("enum"),
      "@application": root,
      "@main": resolve("src/main"),
      "@preload": resolve("src/preload"),
      "@resources": resolve("src/resources"),
    },
  },
  base: "./",
  build: {
    outDir:resolve("dist/application"),
    //默认情况下 outdir在root下时 为true 每次打包会清空outdir 否则会报错 但我们是脚手架 项目架构肯定不会和原版一样 所以这边手动设成true
    emptyOutDir: true,
    target: "esnext",
    //禁用 gzip 压缩大小报告  会提高大型项目的构建性能
    reportCompressedSize: false,
    //多少大小的chunk触发警报
    chunkSizeWarningLimit: 1500,
    //自定义底层的 Rollup 打包配置
    rollupOptions: {
      output: {
        // 入口文件名
        entryFileNames: "assets/[name].js",
        //代码分割
        manualChunks: {
          vue: ["vue", "vue-router"],
          elementPls: ["element-plus"],
        },
      },
    },
  },
  server: {},
  plugins: [TransCssModulePlugin({
    excludeFilePaths:[
      /application\/App/
    ]
  }),vuePlugin(),vueJsx()],
  optimizeDeps: {},
  define:{
    __APP_ENV__:JSON.stringify(Env.envConfig)
  },
  css:{
    modules:{
      localsConvention:'camelCaseOnly',
    }
  }
});
